#include "stdafx.h"
#include "MeshObjectBase.h"
#include "ogre\ogrewidget.h"

MeshObjectBase::MeshObjectBase(ZMString strObjName)
{
	SetObjName(strObjName);
}


MeshObjectBase::~MeshObjectBase()
{
}

void MeshObjectBase::SetParam(const ZMVector<SharedPointer<UIDataBase>>& vParam)
{
	SetNeedUpdateMesh(true);
	SetParamCore(vParam);
}

void MeshObjectBase::UpdateMeshData(OgreWidget * pWidget, const ZMString& meshName, const ZMString& parentNodeName)
{
	if (m_isNeedUpdateMesh)
	{
		m_isNeedUpdateMesh = false;
		pWidget->RemoveNodeData(meshName ==""? GetObjName (): meshName);
		ZMVector<MeshObjectBase::suDrawMesh> vDrawMesh = GetMeshData(meshName);
		set<ZMString> sortNodeName;
		for (MeshObjectBase::suDrawMesh drawMesh : vDrawMesh)
		{
			if (sortNodeName.find(drawMesh.m_strNodeName) == sortNodeName.end())
			{
				pWidget->CreateOrGetNode(parentNodeName, drawMesh.m_strNodeName);
				sortNodeName.insert(drawMesh.m_strNodeName);
			}
		}
		for (MeshObjectBase::suDrawMesh drawMesh : vDrawMesh)
		{
			pWidget->AddMeshData(parentNodeName, drawMesh.m_strNodeName, drawMesh.m_strMatName, *(drawMesh.m_pMeshData));
		}
	}
}